<template>
  <div class="app-container">
    <el-form ref="submitParam" :model="submitParam" :rules="rules" label-width="140px">
      <el-row type="flex">
        <el-col :offset="4" :span="12">
          <el-form-item label="发起清算行：" prop="brno">
            <el-select style="width: 100%" v-model="submitParam.brno" placeholder="" @visible-change="change">
              <el-option
                v-for="option in brNoList"
                :key="option.code"
                :label="`${option.code}-${option.text}`"
                :value="option.code"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-form ref="submitParams" :model="submitParams" :rules="rules" label-width="140px">
      <el-row type="flex">
        <el-col :offset="4" :span="12">
          <el-form-item label="打包方式：" prop="relationship">
            <el-select style="width: 100%" v-model="submitParams.relationship" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.RELATIONSHIP"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div v-if="submitParams.relationship != '0'">
      <el-row type="flex">
        <el-col :offset="4" :span="12">
          <el-form-item label="打包时机选择：" prop="timeType">
            <el-select style="width: 100%" v-model="submitParams.timeType" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.TIME_TYPE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex"  v-if="submitParams.relationship == '2'">
        <el-col :offset="4" :span="12">
          <el-form-item label="打包起点笔数：" prop="miniRecords">
            <el-input v-model="submitParams.miniRecords" placeholder="" disabled />
          </el-form-item>
        </el-col>
      </el-row>
   <div v-if="submitParams.relationship != '0' && submitParams.timeType != '1'">
      <el-row type="flex">
        <el-col :offset="4" :span="12">
          <el-form-item label="固定间隔打包(分钟)：" prop="fixInterval">
            <el-input v-model="submitParams.fixInterval" placeholder="" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :offset="4" :span="6">
          <el-form-item label="起始时间点  小时：" prop="hour1">
            <el-select style="width: 100%" v-model="submitParams.hour1" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.HOUR"
                :key="dict.value"
                :label="`${dict.value}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="分钟：" prop="minute1">
            <el-select style="width: 100%" v-model="submitParams.minute1" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.MINUTE"
                :key="dict.value"
                :label="`${dict.value}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :offset="4" :span="6">
          <el-form-item label="结束时间点  小时：" prop="hour2">
            <el-select style="width: 100%" v-model="submitParams.hour2" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.HOUR"
                :key="dict.value"
                :label="`${dict.value}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="分钟：" prop="minute2">
            <el-select style="width: 100%" v-model="submitParams.minute2" placeholder="" disabled>
              <el-option
                v-for="dict in dictMap.MINUTE"
                :key="dict.value"
                :label="`${dict.value}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
   </div>
      <el-row type="flex">
        <el-col :offset="4" :span="12">
          <el-form-item label="录入操作员：" prop="mdTlrno">
            <el-input v-model="submitParams.mdTlrno" placeholder="" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="4" :span="12">
          <el-form-item label="录入时间：" prop="mdDate">
            <el-date-picker
              v-model="submitParams.mdDate"
              type="datetime"
              value-format="yyyyMMddHHmmss"
              placeholder=""
              disabled
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
        <div v-if="submitParams.relationship != '0' && submitParams.timeType != '2'">
      <ht-table
        ref="dataTable"
        :showSerialNumber="false"
        :multi-select="false"
        :opButtonList="opButtonList"
        :reqConfig="reqConfig"
        :initData="false"
        :queryParams="queryParams"
        :tableBindColumns="tableBindColumns"
      ></ht-table>
        </div>
      </div>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="approveFn" :loading="isLoading">审核</el-button>
      <el-button type="warning" @click="rejectFn" :loading="isLoading">拒绝</el-button>
    </div>
  </div>
</template>

<script>
import { apiUrlConfig, detailsQuery, queryUrl, approve, reject } from "@/api/cnaps/bizMng/beps_bale_method_approve.js";
import { listPageMixin } from "@/libs/listPageMixin";
export default {
  name: "generalInformationEntry",
  mixins: [listPageMixin],
  components: {},
  computed: {},
  data() {
    return {
      reqConfig: apiUrlConfig,
      queryParams: {
        brno: "",
      },
      brNoList: [],
      isLoading: false,
      tableBindColumns: [{ label: `固定时间点列表`, prop: "fixTimeList", width: "1300", align: "center" }],
      // 录入参数
      submitParam: {
        brno: "",
      },
      submitParams: {
        relationship: "",
        timeType: "",
        miniRecords: "",
        fixInterval: "",
        hour1: "",
        minute1: "",
        hour2: "",
        minute2: "",
      },
      searchFormDictList: ["RELATIONSHIP", "TIME_TYPE", "HOUR", "MINUTE"],
      rules: {
        brno: [{ required: true, message: "不能为空", trigger: "change" }],
      },
    };
  },
  created() {
    queryUrl().then((res) => {
      this.brNoList = res.result;
    });
  },
  mounted() {},

  methods: {
    change() {
      this.queryParams.brno = this.submitParam.brno;
      this.$refs.dataTable.doQuery();
      detailsQuery(this.brNoList[0].code).then((res) => {
        this.submitParams = res.result;
      });
    },
    /** 审核按钮 */
    approveFn: function () {
      this.$refs["submitParam"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          approve(this.submitParams)
            .then(() => {
              this.msgSuccess("审核成功");
              this.isLoading = false;
              this.reset();
            })
            .catch(() => {
              this.isLoading = false;
            });
        }
      });
    },
    //拒绝按钮
    rejectFn: function () {
      this.$refs["submitParam"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          reject(this.submitParams)
            .then(() => {
              this.msgSuccess("拒绝成功");
              this.isLoading = false;
              this.reset();
            })
            .catch(() => {
              this.isLoading = false;
            });
        }
      });
    },
    // 表单重置
    reset() {
      this.submitParams = {};
      this.resetForm('submitParam');
      this.change();
    },
  },
};
</script>
<style>
.app-container {
  overflow: scroll;
}

.dialog-footer {
  margin: 10px 0;
  text-align: center;
}
hr {
  border-bottom: 0px;
  margin-bottom: 25px;
}
</style>
